package bit_0525_0312;

import java.util.Stack;

public class Solution_0312 {
    public boolean isValid(String s) {
        Stack<Character> stack1 = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char ret = s.charAt(i);
            if (ret == '(' || ret == '[' || ret == '{') {
                stack1.push(ret);
            }else {
                if (!stack1.empty()) {
                    char tmp = stack1.peek();
                    if (tmp == '(' && ret == ')' || tmp == '[' && ret == ']' || tmp == '{' && ret == '}') {
                        stack1.pop();
                    }else {
                        return false;
                    }
                }else {
                    return false;
                }

            }
        }
        return stack1.empty();
    }
}
